#include "StdAfx.h"
#include "ProtocolBuffer.hpp"


HpsFramework::Network::Protocol::ProtocolBuffer::ProtocolBuffer() : _bufferPtr ( NULL ), _bufferSize ( 0 )
{

}

HpsFramework::Network::Protocol::ProtocolBuffer::ProtocolBuffer( byteptr ptr, size len ) : _bufferPtr ( NULL ), _bufferSize ( 0 )
{
	this->set ( ptr, len );
}

HpsFramework::Network::Protocol::ProtocolBuffer::~ProtocolBuffer()
{
	this->reset();
}

byteptr HpsFramework::Network::Protocol::ProtocolBuffer::getBuffer()
{
	return this->_bufferPtr;
}

size HpsFramework::Network::Protocol::ProtocolBuffer::getSize()
{
	return this->_bufferSize;
}

void HpsFramework::Network::Protocol::ProtocolBuffer::set( byteptr ptr, size len )
{
	this->reset();
	this->_bufferSize = len;
	this->_bufferPtr = new byte[len];
	CopyMemory ( this->_bufferPtr, ptr, this->_bufferSize );
}

void HpsFramework::Network::Protocol::ProtocolBuffer::create ( size len )
{
	this->reset();
	this->_bufferSize = len;
	this->_bufferPtr = new byte[len];
}

void HpsFramework::Network::Protocol::ProtocolBuffer::reset()
{
	if(this->_bufferPtr != NULL)
	{
		delete[] this->_bufferPtr;
	}
	this->_bufferPtr = NULL;
	this->_bufferSize = 0;
}
